<template>
	<view :data-theme="themeStyle">
		<mescroll-uni @getData="getData" class="member-point">
			<view slot="list">
				<view class="index_bg">
					<!-- #ifndef H5 -->
					<!-- <view class="head-nav" :class="{ active: isIphoneX }"></view> -->
					<!-- #endif -->
					<view class="store-list"  v-if="storeId && dataList">
						<view class="list-title">当前门店</view>
						<view class="list-content">
							<view class="list-item"  @click.stop="selectStore(store.store_id)">
								<view class="item-info">
									<view class="item-title">
										<text class="title">{{ store.store_name }}</text>
									</view>
									<view class="item-address">{{ store.full_address + store.address }}</view>
									<view class="item-time" v-if="store.open_date">营业时间：{{ store.open_date }}</view>
								</view>
								<view class="item-right"><text class="item-right-text">查看详情</text><text class="iconfont iconright"></text></view>
							</view>
						</view>
					</view>

					<!-- 门店列表 -->
					<view class="store-list">
						<view class="list-title">附近门店</view>
						<view class="list-content">
							<view class="list-item" v-for="(item, index) in dataList" :key="index">
								<view class="item-info" @click="storeTap(item)">
									<view class="item-title">
										<text class="title">{{ item.store_name }}</text>
										<text class="distance" v-if="item.distance">
											<text class="map-icon iconweizhi iconfont"></text>距离{{ item.distance > 1 ? item.distance + 'km' : item.distance * 1000 + 'm' }}
										</text>
									</view>
									<view class="item-address">{{ item.full_address + item.address }}</view>
									<view class="item-time" v-if="item.open_date">营业时间：{{ item.open_date }}</view>
								</view>
								<view class="item-right"><text class="item-right-text" @click.stop="selectStore(item.store_id)">查看详情</text><text class="iconfont iconright"></text></view>
								<view class="line" v-if="index != dataList.length - 1"></view>
							</view>
						</view>
					</view>
				</view>
			</view>
		</mescroll-uni>
		<loading-cover ref="loadingCover"></loading-cover>
		
	</view>
</template>

<script>
import globalConfig from '@/common/js/golbalConfig.js';
export default {
	components: {},
	data() {
		return {
			searchText: '',
			dataList: [],
			isNetwork: 1, //是否可以继续请求
			isAll: false,
			latitude: null, // 纬度
			longitude: null, // 经度
			store: {},
			storeId: 0,
			isIphoneX: false
		};
	},
	onLoad() {
		this.isIphoneX = this.$util.uniappIsIPhoneX();
		this.store = uni.getStorageSync('store') ? uni.getStorageSync('store') : {};
		if (this.store) this.storeId = this.store.store_id;
		if (uni.getStorageSync('location')) {
			this.latitude = uni.getStorageSync('location').latitude;
			this.longitude = uni.getStorageSync('location').longitude;
		}
	},
	mixins: [globalConfig],
	methods: {
		navigateBack() {
			this.$util.redirectTo('/pages/index/index/index', {}, 'redirectTo');
		},
		search() {},
		getData(mescroll) {
			if (!this.isNetwork) {
				mescroll.endSuccess(0);
				return;
			}
			if (this.isAll) {
				mescroll.endSuccess(0);
				return;
			}
			this.isNetwork = 0;
			let data = {
				page: mescroll.num,
				page_size: mescroll.size
			};
			if (this.latitude && this.longitude) {
				data.latitude = this.latitude;
				data.longitude = this.longitude;
			}
			this.$api.sendRequest({
				url: '/api/store/page',
				data: data,
				success: res => {
					this.isNetwork = 1;
					if (this.$refs.loadingCover) this.$refs.loadingCover.hide();
					let newArr = [];
					let msg = res.message;
					if (res.code == 0 && res.data) {
						newArr = res.data.list;
					} else {
						this.$util.showToast({ title: msg });
					}
					mescroll.endSuccess(newArr.length);
					//设置列表数据
					if (mescroll.num == 1) this.dataList = []; //如果是第一页需手动制空列表
					this.dataList = this.dataList.concat(newArr); //追加新数据
					if (this.dataList.length == res.data.count) {
						this.isAll = true;
					}
				},
				fail: res => {
					mescroll.endErr();
					if (this.$refs.loadingCover) this.$refs.loadingCover.hide();
				}
			});
		},
		//获取门店详情
		getInfo() {
			let data = {
				store_id: this.storeId
			};
			if (this.latitude && this.longitude) {
				data.latitude = this.latitude;
				data.longitude = this.longitude;
			}
			this.$api.sendRequest({
				url: '/api/store/info',
				data: data,
				success: res => {
					if (res.data) {
						this.store = res.data;
						uni.setStorageSync('store', this.store);
					}
				}
			});
		},
		storeTap(item) {
			uni.setStorageSync('store', item);
			this.$util.redirectTo('/pages/index/index/index', {}, 'reLaunch');
		},
		selectStore(e) {
			let id = e ? e : this.storeId;
			this.$util.redirectTo('/otherpages/index/storedetail/storedetail', { store_id: id, back: '/otherpages/index/storelist/storelist' });
		}
	}
};
</script>

<style lang="scss">
.index_bg {
	width: 100%;
	height: 422rpx;
	background-size: 100% 100%;
}

.head-nav {
	width: 100%;
	height: var(--status-bar-height);
}

.head-nav.active {
	padding-top: 40rpx;
}
.store-list {
	width: 100%;
	padding: 0 30rpx;
	box-sizing: border-box;
	margin-top: 20rpx;
	padding-bottom: 20rpx;
	.line {
		width: 630rpx;
		margin: 0 auto;
		height: 1px;
		background-color: $color-line;
		position: absolute;
		bottom: 0;
	}
	.list-title {
		width: 100%;
		font-size: 30rpx;
		color: $color-title;
		font-weight: 500;
		line-height: 1;
		margin: 52rpx 0 24rpx;
	}

	.list-content {
		width: 100%;
		background: #fff;
		border-radius: 10rpx;
		box-sizing: border-box;
		overflow: hidden;

		.list-item {
			position: relative;
			width: 100%;
			padding: 40rpx 30rpx;
			box-sizing: border-box;
			.item-info {
				height: 100%;
				display: flex;
				flex-direction: column;
				margin-right: 24rpx;
				font-size: $font-size-tag;
				.item-title {
					display: flex;
					flex-direction: column;
					justify-content: space-between;
					font-size: $font-size-base;
					color: $color-title;
					line-height: 1;

					.title {
						max-width: 240rpx;
						overflow: hidden;
						text-overflow: ellipsis;
						white-space: nowrap;
						font-size: $font-size-base;
						color: $color-title;
					}

					.distance {
						margin-top: 22rpx;
						font-size: $font-size-tag;
						color: $color-title;
						.map-icon{
							margin-right: 12rpx;
							font-size: $font-size-base;
							color: $color-title;
						}
					}
				}

				.item-time {
					font-size: $font-size-tag;
					color: $color-tip;
					margin-top: 20rpx;
					line-height: 1;
				}

				.item-address {
					margin-top: 22rpx;
					font-size: $font-size-tag;
					color: $color-tip;
					line-height: 35rpx;

					display: -webkit-box;
					-webkit-box-orient: vertical;
					-webkit-line-clamp: 2;
					overflow: hidden;
				}
			}

			.item-right {
				position: absolute;
				right: 30rpx;
				top: 30rpx;
				display: flex;
				justify-content: center;
				align-items: center;
				.item-right-text{
					line-height: 1;
					color: $color-title;
					font-size: $font-size-tag;
					margin-bottom: 6rpx;
				}
				.iconfont {
					color: $color-tip;
				}
			}
		}
	}
}
</style>
